<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/28
 * Time: 14:54
 */

namespace app\common\model\mall;

use app\common\model\TimeModel;


class ItemOrder extends TimeModel
{
    protected $deleteTime = 'delete_time';


    /**
     * 关联用户
     */
    public function User(){
        return $this->belongsTo('app\common\model\user\WxUsers','user_id','id')->field('id,nick_name,phone');
    }

    /*
     * 关联订单地址
     * */
    public function Address(){
        return $this->belongsTo('app\common\model\user\Address','address_id','id');
    }
    /**
     * 获取用户订单商品列表
     */
    public function Lists(){
        return $this->hasMany('app\common\model\mall\ItemOrderList','order_id','id');
    }

    /**
     * 获取用户订单商品所属商家
     */
    public function Store(){
        return $this->belongsTo('app\common\model\mall\Store','store_id','id')->field('id,name');
    }
    /***
     * 关联app_id
     * @param \think\Model $data
     */
    public static function onAfterInsert($data){

        //$self = new static();
        $article = self::withoutGlobalScope()->find($data->id);

        $article->withoutGlobalScope()->where('id',$data->id)->save(['app_id'=>self::get_appId()]);

    }
}